using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace FrameworkX.ObjectSpace.Validation
{
    public class ReguarExpressionAttribute : ValidationAttribute
    {
        private string _expression = string.Empty;
        public ReguarExpressionAttribute(string expression)
        {
            this._expression = expression;
        }

        public override ValidationResult Validate(string propertyName, string value)
        {
            Regex regex = new Regex(this._expression);
            if (!regex.Match (value).Success)
            {
                return new ValidationResult(false,
                    string.Format("Invalid input for {0}.",
                    Util.GetSpacedStringFromWordCapitalizedString(propertyName)));
            }
            else
            {
                return new ValidationResult(true);
            }
        }
    }
}
